﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QuanLiSinhVienThucTap
{
    public partial class QuanLySinhVien : DevComponents.DotNetBar.Metro.MetroForm
    {
        public QuanLySinhVien()
        {
            InitializeComponent();
        }

        private void groupPanel1_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxEx2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void labelX8_Click(object sender, EventArgs e)
        {

        }

        private void groupPanel1_Click_1(object sender, EventArgs e)
        {

        }

        private void labelX13_Click(object sender, EventArgs e)
        {

        }

        private void superTabControlPanel1_Click(object sender, EventArgs e)
        {

        }

        private void dataSV_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void QuanLySinhVien_Load(object sender, EventArgs e)
        {
            dataSV.DataSource = XuliLenh.dulieusinhvien("SinhVien");
            //superTabItem1.Focus();
            //superTabControl1.Focus();
            cbmalop.DataSource = XuliLenh.Maloc("lop", "malop");
            cbtimlop.DataSource = XuliLenh.Maloc("lop", "malop");
            cbMaNhom.DataSource = XuliLenh.Maloc("nhom", "manhom");
        }

        private void superTabControl1_SelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
        {
        
        }

        private void dataSV_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection hangchon = dataSV.SelectedRows;
            CBNam.CheckValue = false;
            CbNu.CheckValue = false;
            int a = -1;
            if (hangchon.Count > 0 && hangchon.Count < 2)
            {
                DataGridViewRow chonhang = hangchon[0];
                txtMaDVTT.Text = chonhang.Cells["madvtt"].Value.ToString();
                txtMaSV.Text = chonhang.Cells["Masv"].Value.ToString();
                txtTenSV.Text = chonhang.Cells["Tensv"].Value.ToString();
                txtNoiSinh.Text = chonhang.Cells["noisinh"].Value.ToString();
                txtSoDT.Text = chonhang.Cells["dienthoai"].Value.ToString();
                txtEmail.Text = chonhang.Cells["Email"].Value.ToString();
                txtDiaChi.Text = chonhang.Cells["diachi"].Value.ToString();
                dtNgaySinh.Value = DateTime.Parse(chonhang.Cells["ngaysinh"].Value.ToString());
                if (chonhang.Cells["gioitinh"].Value.ToString()=="Nam"|chonhang.Cells["gioitinh"].Value.ToString()=="nam")
                {
                    CBNam.CheckValue = true;
                }
                else
                {
                    CbNu.CheckValue = true;
                }
                cbmalop.DataSource = XuliLenh.Maloc("lop","malop");
                 {
                   for (int i=0;i<cbmalop.Items.Count;i++)
                   {
                       if (chonhang.Cells["malop"].Value.ToString() == cbmalop.Items[i].ToString())
                       {
                           a = i;
                           break;
                       }

                  }
                   cbmalop.SelectedIndex=a;
                   a = -1;
                     cbMaNhom.DataSource = XuliLenh.Maloc("nhom", "manhom");
                     {
                         for (int j = 0; j < cbMaNhom.Items.Count; j++)
                         {
                             if (chonhang.Cells["manhom"].Value.ToString() == cbMaNhom.Items[j].ToString())
                             {
                                 a = j;
                                 break;
                             }
                         }
                     }
                     cbMaNhom.SelectedIndex = a;
                 }
            }
        }

        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtMaDVTT_TextChanged(object sender, EventArgs e)
        {

        }

        private void CBNam_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void btnTimSV_Click(object sender, EventArgs e)
        {
          //  dataSV.DataSource = XuliLenh.loctimlop("sinhvien",cbtimlop.SelectedItem.ToString());
            //dataSV.DataSource = XuliLenh.loctimten("sinhvien", txtTimTen.Text.ToString());
            dataSV.DataSource = XuliLenh.loctimma("sinhvien", txtTimMa.Text.ToString());

        }

        private void txtTimTen_TextChanged(object sender, EventArgs e)
        {

        }

        private void superTabControlPanel2_Click(object sender, EventArgs e)
        {

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void Loaddatasinhvien()
        {
            dataSV.DataSource = XuliLenh.loaddulieu("sinhvien");
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaSV.Text != "")
            {
                if (MessageBox.Show("Bạn chắc muốn thêm không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    if (CBNam.Checked == true)
                        XuliLenh.themsv("sinhvien", txtMaSV.Text, txtTenSV.Text, dtNgaySinh.Value,txtNoiSinh.Text,txtDiaChi.Text,txtSoDT.Text ,"Nam", txtEmail.Text, cbmalop.SelectedValue.ToString(),cbMaNhom.SelectedValue.ToString(),txtMaDVTT.Text);
                    else
                    {
                        XuliLenh.themsv("sinhvien", txtMaSV.Text, txtTenSV.Text, dtNgaySinh.Value, txtNoiSinh.Text, txtDiaChi.Text, txtSoDT.Text, "Nữ", txtEmail.Text, cbmalop.SelectedValue.ToString(), cbMaNhom.SelectedValue.ToString(), txtMaDVTT.Text);
                    }
                    Loaddatasinhvien();
                }
            }
        }

        private void BtnXoa_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Bạn chắc muốn xóa không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                DialogResult.Yes)
            {
                if (txtMaSV.Text != "")
                {
                    XuliLenh.xoaSV("sinhvien", txtMaSV.Text);
                    Loaddatasinhvien();
                    txtMaSV.Clear();
                    txtTenSV.Clear();
                    txtSoDT.Clear();
                    txtDiaChi.Clear();
                    txtEmail.Clear();

                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập mã sách cần xóa!!hãy chọn dòng bạn muốn xóa", "Lỗi");
                    return;
                }
            }
        }

        private void colorPickerDropDown1_SelectedColorChanged(object sender, EventArgs e)
        {

        }

        private void superTabControlPanel5_Click(object sender, EventArgs e)
        {

        }          
    }
}